package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-05 00:50
 **/
public class LeetCode372 {

    public int superPow(int a, int[] b) {
        long res = 1;
        int mod = 1337;
        for (int i : b) {
            res = mypow(res, 10, mod) * mypow(a, i, mod);
        }
        return (int) (res % mod);
    }

    long mypow(long a, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                res = res * a % mod;
            }
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

}
